import time

from fastapi import FastAPI,Request,Response
from fastapi.staticfiles import StaticFiles

app11 = FastAPI()



@app11.middleware('http')
async def m2(request:Request,call_next):
    print('m2 请求代码块')

    response = await call_next(request)

    print('m2 响应代码块')
    return response

@app11.middleware('http')
async  def m1(request: Request,call_next):
    print('m1 请求代码块')
    start = time.time()
    response = await call_next(request)
    end = time.time()
    print('m1 响应代码块')
    print(f'程序执行完成，共耗时：{(end-start)}毫秒')
    return response



@app11.get('/goods')
async def getGoods():
    time.sleep(3)
    print('getGoods方法执行了')
    return {
        'goods':['鞋子','图书','水杯']
    }

if __name__ == '__main__':
    import uvicorn
    uvicorn.run('app11_middle:app11', host='127.0.0.1', port=8000)